package com.xuyuan.arithmetic.bit;


import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

public class BasicBitOperation {

    @Test
    public void test1() {
        // 0000 0100
        int a = 4;
        System.out.println(a);
        a |= (1 << 1); // 第二位变成1

        a &= (~(1 << 1)); // 第二位变成0

        System.out.println(a);
    }

    @Test
    public void test2() {
        // 0000 0100
        // 1000 0100

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
        list.forEach(i -> System.out.println(i & -i));
    }

    @Test
    public void test3() {
        double positiveInfinity = Double.POSITIVE_INFINITY;
        double negativeInfinity = Double.NEGATIVE_INFINITY;

        double result = Double.POSITIVE_INFINITY / 2.0;

        System.out.println("Positive Infinity: " + positiveInfinity);
        System.out.println("Negative Infinity: " + negativeInfinity);
        System.out.println("Result of division by 2: " + result);

        if (Double.isInfinite(result)) {
            System.out.println("Result is infinite.");
        }
    }


}
